package net.youyi.crazycopyer.fragment;

import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatTextView;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import net.youyi.crazycopyer.R;


/**
 * Created by xzp on 15/11/9.
 */
public class VideoDetailFragment extends BaseFragment{
    private AppCompatTextView mTagText;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRootView=inflater.inflate(R.layout.fragment_video_detail,container,false);
        mTagText= (AppCompatTextView) mRootView.findViewById(R.id.tag_text);
        SpannableStringBuilder builder=new SpannableStringBuilder();
        SpannableString spanStr1=new SpannableString("DNF");
        spanStr1.setSpan(new MyClickableSpan("DNF"),0,3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.append(spanStr1);
        builder.append(", ");
        SpannableString spanStr2=new SpannableString("陆行鸟~~");
        spanStr2.setSpan(new MyClickableSpan("陆行鸟~~"), 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.append(spanStr2);
        mTagText.setText(builder);
        return mRootView;
    }
    private class MyClickableSpan extends ClickableSpan{
        private String mText;
        public MyClickableSpan(String text) {
            mText=text;
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            TypedArray array = mRootView.getContext().getTheme().obtainStyledAttributes(new int[] {
                    android.support.v7.appcompat.R.attr.colorPrimary
            });
            int primaryColor=array.getColor(0, Color.WHITE);
            array.recycle();
            ds.setColor(primaryColor);
        }

        @Override
        public void onClick(View widget) {

        }
    }

}
